// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var Fabtabs = Class.create();
Fabtabs.prototype = {
   initialize : function(element) {
          this.element = $(element);
                var options = Object.extend({}, arguments[1] || {});
              this.menu = $A(this.element.getElementsByTagName('a'));
           this.show(this.getInitialTab());
          this.menu.each(this.setupTab.bind(this));
 },
        setupTab : function(elm) {
                Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
  },
        activate :  function(ev) {
                var elm = Event.findElement(ev, "a");
           Event.stop(ev);
		   location.href = elm;
           this.show(elm);
           this.menu.without(elm).each(this.hide.bind(this));
        },
        hide : function(elm) {
            $(elm).removeClassName('active');
             $(this.tabID(elm)).removeClassName('active');
    },
        show : function(elm) {
            $(elm).addClassName('active');
                $(this.tabID(elm)).addClassName('active');
  },
        tabID : function(elm) {
           return elm.href.match(/#(\w.+)/)[1];
      },
        getInitialTab : function() {
              if(document.location.href.match(/#(\w.+)/)) {
                     var loc = RegExp.$1;
                      var elm = this.menu.find(function(value) { return value.href.match(/#(\w.+)/)[1] == loc; });
                      return elm || this.menu.first();
          } else {
                  return this.menu.first();
         }
 }
}
Event.observe(window,'load',function(){ new Fabtabs('tabs'); },false);

function tabs(obj) {
	var element = $(obj.title);
	var parent = obj.parentNode;
	var stepTabs = $A(parent.getElementsByTagName('li'));
	stepTabs.each(function(item) {
			if ($(item.title).hasClassName('active')) {
				$(item.title).removeClassName('active');
				item.removeClassName('active');
			} else if (item.title == obj.title) {	
				element.addClassName('active');
				obj.addClassName('active');
				//new Effect.SlideDown(element);
			}
		});
}

function addToForm(form_id,el) {
	$(form_id).value = el.innerHTML;
}

function restart(obj) {
	var divs = $(obj.up('div',1).identify()).nextSiblings();
	divs.each(function(item) {
		item.hide();
	})
}

function loading() {
	$('home').down('div',0).toggleClassName('working');
}